<?php
//decode by QQ:735674691 http://bbs.yaoduoli.com/

if (!defined('INDEX')) {
    exit('Access Denied');
}function m_act_wap_search(){	global $duoduo,$dd_tpl_data;	$webset = $duoduo->webset;	$dduser = $duoduo->dduser;	include(DDROOT.'/comm/goods.class.php');	$goods_class=new goods($duoduo);	$page=$_GET['page']?$_GET['page']:1;	$code=$dd_tpl_data['bsm'];	$search_method = (int)$_GET['search_method'] ? (int)$_GET['search_method'] : 0;	$cid=(int)$_GET['cid'];	$pagesize=$dd_tpl_data['shuliang'];	$fromnum=($page-1)*$pagesize;		$bankuai=dd_get_cache('bankuai');	$where='1';	$title='全部商品';    $q=$_GET['q'];	if($q!=''){		$where.=' and title like "%'.$q.'%"';	}	if ($search_method == 0) {		$where .= ' and laiyuan_type in (1,2)';	} else {		$where .= ' and laiyuan_type = 3';	}	$shuju_data=$duoduo->select_all('goods','*',$where);	if (empty($shuju_data)) echo '<script>alert("搜索结果为空，请重新搜索！");location.href="/m";</script>';	$parameter['shuju_data'] = $shuju_data;	unset($dd_tpl_data);	return $parameter;}
function act_wap_miaozhe(){
	global $duoduo,$dd_tpl_data;
	$webset = $duoduo->webset;
	$dduser = $duoduo->dduser;
	include(DDROOT.'/comm/goods.class.php');
	$goods_class=new goods($duoduo);
	$page=$_GET['page']?$_GET['page']:1;
	$code=$dd_tpl_data['bsm'];
	$cid=(int)$_GET['cid'];
	$pagesize=$dd_tpl_data['shuliang'];
	$fromnum=($page-1)*$pagesize;
	
	$bankuai=dd_get_cache('bankuai');
	$where='1';
	$title='全部商品';
    $q=$_GET['q'];
	if($q!=''){
		$where.=' and title like "%'.$q.'%"';
	}
	if($code!=''){
		$where.=' and code="'.$code.'"';
		$title=$bankuai[$code]['title'];
	}
	if($cid>0){
		$where.=' and cid="'.$cid.'"';
		$title=$bankuai[$code]['title'];
	}
	$slides=$duoduo->select_all('slides','*','cid="wap" and hide=0 order by sort=0 asc,sort asc,id desc');
	
	if(!empty($slides)){
		foreach($slides as $k=>$row){
			if(preg_match('#^http://(item\.taobao\.com)|(detail\.tmall\.com)|(h5\.m\.taobao\.com)|(detail\.m.tmall\.com)#',$row['url'])){
				$iid=(float)get_tao_id($row['url']);
				if($iid>0){
					$slides[$k]['url']=$row['url'];
				}
			}
			else if(is_url($row['url'])){
				$slides[$k]['url']=$row['url'];
			}
			else{
				$slides[$k]['url']=$row['url'];
				$slides[$k]['waibu_url']=1;
			}
		}
	}

	$shuju_data=$goods_class->index_list(array('code'=>$code),$pagesize,$page,'(laiyuan_type in(1,2) or domain="jd.com") and '.$where);
	foreach($shuju_data as $k=>$row){
	if($row['is_new']){
	$shuju_data[$k]['xin']='<span class="xinpin"></span>';
	 }
	 else{
	 $shuju_data[$k]['xin']='';
	 }
	if($row['price_man']>0){
	 $shuju_data[$k]['quan_hou']='<span class="title-tips01">券后</span>';
	 $shuju_data[$k]['youhuiquan']='<a href="'.$lq_url.'"><div class="quan_img"><span class="num_money left">'.$row['price_jian'].'</span></div></a>';
	 }
	 else{
	 $shuju_data[$k]['quan_hou']='';
	 $shuju_data[$k]['youhuiquan']=$row['discount_price'];
	 }
	  if($row['quan_total']>0){
	 $shuju_data[$k]['quanhoujia']=''.$row['discount_price']-$row['price_jian'].'';
	 $shuju_data[$k]['quanhoufan']=''.number_format((($row['discount_price']-$row['price_jian'])*$row['fanli_bl']/100),2).'';
	 }else{
	 $shuju_data[$k]['quanhoujia']=''.$row['discount_price'].'';
	 $shuju_data[$k]['quanhoufan']=''.number_format((($row['discount_price']-$row['price_jian'])*$row['fanli_bl']/100),2).'';
	 }
		if($row['id']){
			$shuju_data[$k]['url']=wap_l('goods','view',array('id'=>$row['id'],'rec'=>$dduser['id']));
		}
		else{
			$shuju_data[$k]['url']=wap_l('goods','view',array('iid'=>$row['data_id'],'rec'=>$dduser['id']));
		}
		$shuju_data[$k]['bankuai_title']=$bankuai[$row['code']]['title'];
		$shuju_data[$k]['img']=tb_img($row['img'],500);
	}
	$bankuai=$duoduo->select_all('bankuai','*','status=1 and mobile_status=1 ORDER BY sort =0 ASC');
	foreach($bankuai as $row){
		$bankuai_wap[]=array('img'=>$row['mobile_logo'],'title'=>$row['title'],'code'=>$row['code'],'url'=>wap_l('goods','index',array('code'=>$row['code'])));
	}
	
	if(count($bankuai_wap)>$bankuai_num && count($bankuai_wap)%$bankuai_num!=0){
		$bankuai_wap[]=array('img'=>'m/template/default/inc/images/more.png','title'=>'更多','url'=>wap_l('goods','bankuai'));
	}
	$parameter['shuju_data']=$shuju_data;
	$parameter['code']=$code;
	$parameter['slides']=$slides;
	$parameter['bankuai_wap']=$bankuai_wap;
	$parameter['slide_num']=count($slides);	$parameter['is_search'] = $is_search;
	unset($dd_tpl_data);
	return $parameter;
}